<?php
/**
 * This class is responsible for managing engine behaviours
 * it's only extra functionality from ForageBehaviourHandler is 
 * to restrict added behaviour to ForageEngineBehaviour objects.
 *
 * @author Rob Young <rob@roryoung.co.uk>
 * @package forage.behaviours
 */
class ForageEngineBehaviourHandler extends ForageBehaviourHandler
{
  /**
   * Add a behaviour to this handler.
   *
   * @param ForageEngineBehaviour
   */
  public function addBehaviour($behaviour)
  {
    if (!($behaviour instanceof ForageEngineBehaviour)) {
      throw new InvalidArgumentException("Expecting a ForageEngineBehaviour");
    }
    parent::addBehaviour($behaviour);
  }
}

/**
 * Abstract base class for all behaviours relating to ForageEngine
 * objects.
 *
 * @author Rob Young <rob@roryoung.co.uk>
 * @package forage.behaviours
 */
abstract class ForageEngineBehaviour extends ForageBehaviour
{
  protected $engine;
  protected $pdo;

  public function __construct(PDO $pdo)
  {
    $this->pdo = $pdo;
    $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  }

  public function setEngine(ForageEngineModifiable $engine)
  {
    $this->engine = $engine;
  }
}
